﻿<!-- #Include File="../Include/Admin_Onlogin.asp" -->
<%
ChannelID = Code_CLng(Trim(Request.QueryString("channelid")))
filetype = Code_CLng(Trim(Request.QueryString("filetype")))
Data_Name = "{prefix}Attachment"
strFileName = "Admin_UploadFile_Select.asp?channelid="&ChannelID&"&filetype="&filetype&"&limit="&Code_CLng(Trim(Request("limit")))&"&field_name="&Trim(Request("field_name"))&"&field_value="&Trim(Request("field_value"))&""
Select Case Action
Case Else
	Call Main()
End Select
Set Fso = nothing

Sub Main()
	If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
		dim idnum:idnum=request.form("ids").count
		for i=1 to idnum
			id=trim(request.form("ids")(i))
			id=replace(id,chr(13),"")
			id=replace(id,chr(10),"")
			if i>1 then
				idarr=idarr&","
			end if
			idarr=idarr&id
		next
		Sql = "Select * From ["&Data_Name&"]"
		If idnum=0 Then
			Response.Write "{""code"":0,""msg"":""至少要选择一个文件""}" & vbCrLf
			Response.End()
		ElseIf Code_CLng(idnum)>Code_CLng(request.form("limit")) Then
			Response.Write "{""code"":0,""msg"":""只能选择"&Code_CLng(request.form("limit"))&"个文件，你已经选择"&idnum&"个""}" & vbCrLf
			Response.End()
		Else
			Sql = Sql & " Where id in (" & idarr & ")"
		End If
		Sql = Sql & " Order By ID Desc"
		Call Exe_Conn(Rs,Sql,1)
		totalPut = Rs.RecordCount
		i = 0
		If Rs.BOF And Rs.EOF Then
			data = ""
		Else
			Do While Not Rs.Eof
				If i=0 Then
					If CheckExt( "gif|jpg|jpeg|png|bmp", Rs("fileext") ) Then
						data = data & "{""id"":"""&Rs("id")&""",""name"":"""&Rs("oldname")&""",""file"":"""&Replace(Rs("fullname"),"/","\/")&""",""url"":"""&Replace(Rs("fullname"),"/","\/")&""",""size"":"""&GetSize(Rs("filesize"),"k")&""",""time"":"""&Time_Type(Rs("createdate"),1)&""",""preview"":""<a href=\""javascript:preview_image('"&Replace(Rs("fullname"),"/","\/")&"');\""><img src=\"""&Replace(Rs("fullname"),"/","\/")&"\""><\/a>""}"
					Else
						url = "../Plugins/assets/images/ext/"&Rs("fileext")&".png"
						data = data & "{""id"":"""&Rs("id")&""",""name"":"""&Rs("oldname")&""",""file"":"""&Replace(Rs("fullname"),"/","\/")&""",""url"":"""&Replace(url,"/","\/")&""",""size"":"""&GetSize(Rs("filesize"),"k")&""",""time"":"""&Time_Type(Rs("createdate"),1)&""",""preview"":""<a href=\""javascript:preview_image('"&Replace(Rs("fullname"),"/","\/")&"');\""><img src=\"""&Replace(Rs("fullname"),"/","\/")&"\""><\/a>""}"
					End If
				Else
					If CheckExt( "gif|jpg|jpeg|png|bmp", Rs("fileext") ) Then
						data = data & ",{""id"":"""&Rs("id")&""",""name"":"""&Rs("oldname")&""",""file"":"""&Replace(Rs("fullname"),"/","\/")&""",""url"":"""&Replace(Rs("fullname"),"/","\/")&""",""size"":"""&GetSize(Rs("filesize"),"k")&""",""time"":"""&Time_Type(Rs("createdate"),1)&""",""preview"":""<a href=\""javascript:preview_image('"&Replace(Rs("fullname"),"/","\/")&"');\""><img src=\"""&Replace(Rs("fullname"),"/","\/")&"\""><\/a>""}"
					Else
						url = "../Plugins/assets/images/ext/"&Rs("fileext")&".png"
						data = data & ",{""id"":"""&Rs("id")&""",""name"":"""&Rs("oldname")&""",""file"":"""&Replace(Rs("fullname"),"/","\/")&""",""url"":"""&Replace(url,"/","\/")&""",""size"":"""&GetSize(Rs("filesize"),"k")&""",""time"":"""&Time_Type(Rs("createdate"),1)&""",""preview"":""<a href=\""javascript:preview_image('"&Replace(Rs("fullname"),"/","\/")&"');\""><img src=\"""&Replace(Rs("fullname"),"/","\/")&"\""><\/a>""}"
					End If
				End If
				Rs.MoveNext
				i=i+1
			Loop
			Rs.Close
		End If
		If totalPut = 0 Then
			Response.Write "{""code"":0,""msg"":""已选择"&totalPut&"个文件""}" & vbCrLf
		Else
			Response.Write "{""code"":1,""msg"":""已选择"&totalPut&"个文件"",""data"":{""count"":"""&totalPut&""",""result"":["&data&"]}}" & vbCrLf
		End If
		Response.End()
	Else
		Response.Write "<!DOCTYPE html>" & vbCrLf
		Response.Write "<head>" & vbCrLf
		Response.Write "<title>附件选择</title>" & vbCrlf
		Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'>" & vbCrLf
		Response.Write "<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1'>" & vbCrLf
		Response.Write "<meta name='apple-mobile-web-app-status-bar-style' content='black'>" & vbCrLf
		Response.Write "<meta name='apple-mobile-web-app-capable' content='yes'>" & vbCrLf
		Response.Write "<meta name='format-detection' content='telephone=no'>" & vbCrLf
		Response.Write "<link rel=""stylesheet"" type=""text/css"" href=""../fonts/font-awesome/css/font-awesome.min.css"" />" & vbCrLf
		Response.Write "<link href='../Plugins/layui/css/layui.css' rel='stylesheet' type='text/css' />" & vbCrLf
		Response.Write "<link rel=""stylesheet"" href=""../Style/global.css"" media=""all"">" & vbCrLf
		Response.Write "<link rel=""stylesheet"" href=""../Style/font.css"" media=""all"">" & vbCrLf
		Response.Write "<script type='text/javascript'>" & vbCrLf
		Response.Write "var pc_file = '" & InstallDir & "';" & vbCrLf
		Response.Write "var admin_file = '" & AdminFolder & "/';" & vbCrLf
		Response.Write "</script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../Js/Admin.js'></script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../../Dialog/main.js'></script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../../Dialog/lhgcore.min.js'></script>" & vbCrLf
		Response.Write "<script type='text/javascript' src='../../Dialog/lhgcalendar.min.js'></script>" & vbCrLf
		Response.Write "<script type=""text/javascript"" src=""../Plugins/layui/layui.js""></script>" & vbCrLf
		Response.Write "<script src=""../Plugins/assets/ds.min.js""></script>" & vbCrLf
		Response.Write "</head>" & vbCrlf
		Response.Write "<body>" & vbCrlf
		Response.Write "<form class=""form-horizontal"" method=""post"" role=""form"" id=""myform"" name=""myform"" style=""margin-top:-20px;"">" & vbCrLf
		Response.Write "    <input type=""hidden"" name=""limit"" value="""&Code_CLng(Trim(Request("limit")))&""">" & vbCrlf
		Response.Write "    <div class=""portlet light"" style=""padding: 0;margin: 30px;"">" & vbCrLf
		Response.Write "        <div class=""portlet-title tabbable-line"">" & vbCrLf
		Response.Write "            <div style=""border-bottom: 0px solid #eee;"" class=""portlet-title tabbable-line"">" & vbCrLf
		Response.Write "                <div style=""display: flex;border-bottom: 0px dotted #e2e2e2;margin-bottom: 0!important;margin-right: 0px;"" class=""row  margin-bottom-20 template-download"">" & vbCrLf
		Response.Write "                    <div style=""display: flex;width: 100%;text-align: left"" class=""text-center"">" & vbCrLf
		Response.Write "                        <div>" & vbCrLf
		Response.Write "                            <label>"&SelectInit("field_name",Split("附件ID|附件名称","|"),Split("id|oldname","|"),Trim(Request("field_name")))&"</label>" & vbCrLf
		Response.Write "                            <label>" & vbCrLf
		Response.Write "                                <input type=""text"" class=""form-control"" value="""&Trim(Request("field_value"))&""" id=""field_value"" name=""field_value"">" & vbCrLf
		Response.Write "                            </label>" & vbCrLf
		Response.Write "                            <label><a class=""btn green btn-sm"" href=""javascript:;"" onclick=""dr_fsearch()"">搜索</a></label>" & vbCrLf
		Response.Write "                            <span id=""all"" class=""btn green btn-sm"">全选</span>" & vbCrLf
		Response.Write "                            <span id=""allno"" class=""btn green btn-sm"">全不选</span>" & vbCrLf
		Response.Write "                            <span id=""other"" class=""btn green btn-sm"">反选</span>" & vbCrLf
		Response.Write "                        </div>" & vbCrLf
		Response.Write "                    </div>" & vbCrLf
		Response.Write "                </div>" & vbCrLf
		Response.Write "            </div>" & vbCrLf
		Response.Write "        </div>" & vbCrLf
		Response.Write "        <div class=""portlet-body"">" & vbCrLf
		Response.Write "            <div class=""tab-content"">" & vbCrLf
		Response.Write "                <div class=""tab-pane"" id=""tab_1"">" & vbCrLf
		Response.Write "                    <div role=""presentation"" class=""table table-fc-upload table-striped clearfix"">" & vbCrLf
		Response.Write "                        <div class=""files"">" & vbCrLf
		If ChannelID = "" Then ChannelID = 0
		If ChannelID > 0 Then
			Call GetChannel(ChannelID)
			select case filetype
				case "2":uptype=ChannelUpFileType(3)
				case "3":uptype=ChannelUpFileType(2)
				case "4":uptype="gif|jpg|png|bmp|flv|mp4|swf|mp3|rar|zip|tar|gz|7z|bz2|cab|iso|apk|doc|docx|xls|xlsx|ppt|pptx|pdf|txt|md|xml"
				case "5":uptype=ChannelUpFileType(1)
				case else:uptype=ChannelUpFileType(0)
			end select
		Else
			select case filetype
				case "2":uptype=UploadSetting(23)
				case "3":uptype=UploadSetting(22)
				case "4":uptype="gif|jpg|png|bmp|flv|mp4|swf|mp3|rar|zip|tar|gz|7z|bz2|cab|iso|apk|doc|docx|xls|xlsx|ppt|pptx|pdf|txt|md|xml"
				case "5":uptype="swf"
				case else:uptype=UploadSetting(3)
			end select
		End If
		uptype=split(uptype,"|")
		for i = 0 to ubound(uptype)
			If i = 0 Then
				exts = exts & "'" & uptype(i) & "'"
			Else
				exts = exts & "," & "'" & uptype(i) & "'"
			End If
		next
		Sql = "Select * From ["&Data_Name&"] where fileext in ("&exts&")"
		If ChannelID<>0 Then
			Sql = Sql & " And ChannelID=" & ChannelID & ""
		End If
		If Trim(Request("field_name"))="id" Then
			If Trim(Request("field_name"))<>"" And Trim(Request("field_value"))<>"" Then Sql = Sql & " And id=" & Code_CLng(Trim(Request("field_value"))) & ""
		Else
			If Trim(Request("field_name"))<>"" And Trim(Request("field_value"))<>"" Then Sql = Sql & " And " & Trim(Request("field_name")) & " LIKE '%" & Trim(Request("field_value")) & "%'"
		End If
		Sql = Sql & " Order By ID Desc"
		Call Exe_Conn(Rs,Sql,1)
		If Rs.BOF And Rs.EOF Then
		Else
			If Request("Page") <> "" Then
				CurrentPage = Code_CLng(Request("Page"))
			Else
				CurrentPage = 1
			End If
			MaxPerPage = Code_CLng(Trim(Request("MaxPerPage")))
			If MaxPerPage <= 0 Then MaxPerPage = 14
			totalPut = Rs.RecordCount
			If CurrentPage < 1 Then
				CurrentPage = 1
			End If
			If (CurrentPage - 1) * MaxPerPage > totalPut Then
				If (totalPut Mod MaxPerPage) = 0 Then
					CurrentPage = totalPut \ MaxPerPage
				Else
					CurrentPage = totalPut \ MaxPerPage + 1
				End If
			End If
			If CurrentPage > 1 Then
				If (CurrentPage - 1) * MaxPerPage < totalPut Then
					Rs.Move (CurrentPage - 1) * MaxPerPage
				Else
					CurrentPage = 1
				End If
			End If
			Do While Not Rs.Eof
				If CheckExt( "gif|jpg|jpeg|png|bmp", Rs("fileext") ) Then
					Response.Write "                            <div class=""template-download yl_files_row files_row"">" & vbCrLf
					Response.Write "                                <span class=""checkbox""></span>" & vbCrLf
					Response.Write "                                <input type=""checkbox"" class=""checkboxes"" name=""ids"" value="""&Rs("id")&""" />" & vbCrLf
					Response.Write "                                <img src="""&Rs("fullname")&""">" & vbCrLf
					Response.Write "                                <i class=""size"">"&GetSize(Rs("filesize"),"k")&"</i>" & vbCrLf
					Response.Write "                                <i class=""name"" title="""&Rs("oldname")&"""> "&Rs("oldname")&" </i>" & vbCrLf
					Response.Write "                            </div>" & vbCrLf
				Else
					Response.Write "                            <div class=""template-download yl_files_row files_row"">" & vbCrLf
					Response.Write "                                <span class=""checkbox""></span>" & vbCrLf
					Response.Write "                                <input type=""checkbox"" class=""checkboxes"" name=""ids"" value="""&Rs("id")&""" />" & vbCrLf
					Response.Write "                                <img src=""../Plugins/assets/images/ext/"&Rs("fileext")&".png"">" & vbCrLf
					Response.Write "                                <i class=""size"">"&GetSize(Rs("filesize"),"k")&"</i>" & vbCrLf
					Response.Write "                                <i class=""name"" title="""&Rs("oldname")&"""> "&Rs("oldname")&" </i>" & vbCrLf
					Response.Write "                            </div>" & vbCrLf
				End If
				iCount = iCount + 1
				If iCount >= MaxPerPage Then Exit Do
				Rs.MoveNext
			Loop
			Rs.Close
		End If
		Response.Write "                        </div>" & vbCrLf
		Response.Write "                    </div>" & vbCrLf
		Response.Write "                </div>" & vbCrLf
		Response.Write "            </div>" & vbCrLf
		Response.Write "            <div class=""tab-content"">" & ShowPage(strFileName, totalPut, MaxPerPage, CurrentPage, True, True, "个模板", True) & "</div>" & vbCrLf
		Response.Write "        </div>" & vbCrLf
		Response.Write "    </div>" & vbCrLf
		Response.Write "</form>" & vbCrLf
		Response.Write "<style>" & vbCrLf
		Response.Write "body{-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}" & vbCrLf
		Response.Write ".portlet.light, .portlet.light.bordered {border: none !important;}" & vbCrLf
		Response.Write ".portlet.light {padding: 12px 20px 15px;background-color: #fff;}" & vbCrLf
		Response.Write ".portlet {margin-top: 0;margin-bottom: 25px;padding: 0;border-radius: 4px;}" & vbCrLf
		Response.Write ".portlet.light>.portlet-title {padding: 0;min-height: 48px;}" & vbCrLf
		Response.Write ".portlet>.portlet-title {border-bottom: 1px solid #eee;padding: 0;margin-bottom: 10px;min-height: 41px;-webkit-border-radius: 4px 4px 0 0;-moz-border-radius: 4px 4px 0 0;-ms-border-radius: 4px 4px 0 0;-o-border-radius: 4px 4px 0 0;border-radius: 4px 4px 0 0;}" & vbCrLf
		Response.Write "form .portlet.light .portlet-body {padding: 20px 0px 20px 20px;}" & vbCrLf
		Response.Write ".page-body{user-select:none;}" & vbCrLf
		Response.Write ".form-control{margin-left:10px;}" & vbCrLf
		Response.Write ".files_row{position:relative;width:10%; float:left; margin-bottom:40px; overflow: hidden; text-align: center;margin:10px 20px; height:150px; background-color:#ddd;border-radius: 5px; border:solid 1px #ddd;}" & vbCrLf
		Response.Write ".files_row i.name,.files_row i.size{ color: #fff; height: 20px; line-height: 20px;  position:absolute;  left:0;  font-style: normal; width: 100%!important; font-size: 12px;}" & vbCrLf
		Response.Write ".files_row i.name{ background: #36c6d3; bottom:0px;}" & vbCrLf
		Response.Write ".files_row i.size{ background: #666;bottom:20px;}" & vbCrLf
		Response.Write ".files_row .checkboxes{visibility:hidden; position:absolute; top:5px; left:5px;}" & vbCrLf
		Response.Write ".files_row .checkbox {width:25px; height:25px!important; min-height: 25px!important;position:absolute; top:5px; right:5px;background: url(../Plugins/assets/images/icon_item_hover.png);}" & vbCrLf
		Response.Write ".files_row span{display: none;}" & vbCrLf
		Response.Write ".files_row img{max-width: 100%; }" & vbCrLf
		Response.Write ".files_row:hover i,.files_row:hover img { opacity: 0.6 }" & vbCrLf
		Response.Write ".files_row:hover .mar{ background: #333; }" & vbCrLf
		Response.Write ".files_row:hover .checkbox{ display:block; }" & vbCrLf
		Response.Write ".files_row.on .checkbox {background: url(../Plugins/assets/images/icon_item_cur.png); display:block; }" & vbCrLf
		Response.Write ".files_row.on span{display:block; }" & vbCrLf
		Response.Write ".files_row.on { background: #333; }" & vbCrLf
		Response.Write ".files_row.on i,.files_row.on img{ opacity: 0.3 }" & vbCrLf
		Response.Write ".btn-file {position: absolute;top: 0;right: 0;width: 100%;margin: 0;font-size: 23px;cursor: pointer;opacity: 0;direction: ltr;}" & vbCrLf
		Response.Write "</style>" & vbCrLf
		Response.Write "<script>" & vbCrLf
		Response.Write "var ds = new DragSelect({" & vbCrLf
		Response.Write "	selectables: document.getElementsByClassName('files_row')," & vbCrLf
		Response.Write "	multiSelectMode: true," & vbCrLf
		Response.Write "	//选中" & vbCrLf
		Response.Write "	onElementSelect: function(element){" & vbCrLf
		Response.Write "		$(element).addClass('on').find('input[type=""checkbox""]').prop('checked', true);" & vbCrLf
		Response.Write "	}," & vbCrLf
		Response.Write "	//取消选中" & vbCrLf
		Response.Write "	onElementUnselect: function(element){" & vbCrLf
		Response.Write "		$(element).removeClass('on').find('input[type=""checkbox""]').prop('checked', false);" & vbCrLf
		Response.Write "	}" & vbCrLf
		Response.Write "});" & vbCrLf
		Response.Write "$(function(){" & vbCrLf
		Response.Write "	//区域内的所有可选元素" & vbCrLf
		Response.Write "	var selects = ds.selectables;" & vbCrLf
		Response.Write "	//全选" & vbCrLf
		Response.Write "	$('#all').click(function(){" & vbCrLf
		Response.Write "		ds.setSelection(selects);" & vbCrLf
		Response.Write "	});" & vbCrLf
		Response.Write "	//全不选" & vbCrLf
		Response.Write "	$('#allno').click(function(){" & vbCrLf
		Response.Write "		ds.clearSelection();" & vbCrLf
		Response.Write "	});" & vbCrLf
		Response.Write "	//反选" & vbCrLf
		Response.Write "	$('#other').click(function(){" & vbCrLf
		Response.Write "		ds.toggleSelection(selects);" & vbCrLf
		Response.Write "	});" & vbCrLf
		Response.Write "});" & vbCrLf
		Response.Write "function dr_fsearch() {" & vbCrLf
		Response.Write "	location.href = '?channelid="&ChannelID&"&filetype="&filetype&"&limit="&Code_CLng(Trim(Request("limit")))&"&field_name='+$('#field_name').val()+'&field_value='+$('#field_value').val();" & vbCrLf
		Response.Write "}" & vbCrLf
		Response.Write "</script>" & vbCrLf
		Response.Write "</body>" & vbCrLf & "</html>"
	End If
End Sub

Private Function CheckExt( cfgAllowType, fileType )
	If IsEmpty (cfgAllowType) Then
		CheckExt = true
		 Exit Function
	End If
	cfgAllowType = Split(cfgAllowType, "|")
	For Each ext In cfgAllowType
		If UCase(fileType) = UCase(ext) Then 
			CheckExt = true
			Exit Function
		End If
	Next
	CheckExt = false
End Function
%>